package model;

import javax.microedition.lcdui.Image;

/**
 * Represents a method of transportation that may be used by the user. Every transportation
 * method has a speed associated with it as well as an image representing it.
 *
 * @author rhaq
 * @version 1.00 2009-05-06 Initial submission.
 */
public class Transportation extends Graphical
{
	/** The minimum speed that any transportation object can have. */
	private static final int MIN_SPEED = 1;

	/** The movement speed in units that this transportation allows. */
	private int speed;


	/**
	 * Creates a transportation object and associates the specified image and speed with it.
	 * @param image The image to associate with the transportation object.
	 * @param speed The speed that this transportation object can move at.
	 */
	public Transportation(Image image, int speed)
	{
		super(image);
		safeSpeedAssignment(speed);
	}


	/**
	 * Safe assignment of speed by exception checking to see if a valid speed has been specified.
	 * @param speed The speed specified to check for validity.
	 */
	private void safeSpeedAssignment(int speed)
	{
		if (speed < MIN_SPEED)
			throw new IllegalArgumentException("Invalid speed "+speed+" specified, must be greater than "+MIN_SPEED);

		this.speed = speed;
	}


	/**
	 * Retrieves the speed of this transportation object.
	 * @return The speed of this transportation object.
	 */
	public int getSpeed()
	{
		return speed;
	}


	/**
	 * Sets the speed to the specified value.
	 * @param speed The speed to set of this transportation object.
	 */
	public void setSpeed(int speed)
	{
		safeSpeedAssignment(speed);
	}
}